﻿/// <reference path="../../Geo.CoordinateConverter.ts" />
/// <reference path="../qunit.d.ts" />
//http://toolserver.org/~geohack/geohack.php?pagename=Geographic_coordinate_conversion&params=41_51_1_N_87_57_16_W_

import GeoConverter = Geo.CoordinateConverter;

test("CoordinateConverter Formats 40.446454 -79.976875", function () {

    var expectedResult : GeoConverter.Interfaces.ICoordinateDms = new GeoConverter.Model.CoordinateDmsInfo(
        new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.North, 40, 26, 47.2),
        new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.West, 79, 58, 36.75)
    );

    var formats = new Array();//40.446454 -79.976875
    formats[0] = '40.446454 -79.976875';
    formats[1] = '40.446454,-79.976875';
    formats[2] = '40.446454N 79.976875W';
    formats[3] = '40:26:47.2N 079:58:36.75W';
    formats[4] = '40°26\'47"N 079°58\'37"W';
    formats[5] = '40°26′47″N 079°58′37″W';
    formats[6] = '40d 26\' 47" N 079d 58\' 37" W';
    formats[7] = '40d 26′ 47″ N 079d 58′ 37″ W';
    formats[8] = '40d 26′ 47″ N -079d 58′ 37″';
    formats[9] = '40° 26.78724, -79° 58.61250';	
    formats[10] = '40d 26.78724, -79d 58.61250';
    formats[11] = '40.4464540, -79.9768750';
    formats[12] = '40°26′47″N 079°58′37″W';
    formats[13] = '40°26\'47"N 079°58\'37"W';
    formats[14] = '40d 26\'47" 079d 58\'37"W';
    formats[15] = '40d 26\'47"N 079d 58\'37"W';
    formats[16] = '40d 26′47″N 079°58′37″W';
    formats[17] = '40 26 47 N 079 58 37 W';
    formats[18] = '40 26 47N 079 58 37W';
    formats[19] = 'N 40d 26 47  W 079 58 37';
    formats[20] = 'N40d 26 47 079 58 37W';
    formats[21] = '40d 26 47N 079 58 37W';
    formats[22] = 'N40d 26 47 -079 58 37';
    formats[23] = 'N40* 26.78724\'  W079* 58.61250\''; 
    formats[23] = 'W079* 58.61250\'  N40* 26.78724\''; 

    var dmsConverter: GeoConverter.Interfaces.IParseDms = new GeoConverter.Providers.DecimalAndDmsConverter();
    for (var i = 0; i < formats.length; i++){
        var input: string = formats[i];
        var output : GeoConverter.Interfaces.ICoordinateDms = dmsConverter.ParseCoordinateDms(input);
       
        equal(output.DmsLatitude.DirectionType          ,expectedResult.DmsLatitude.DirectionType       , 'N DirectionType RESULT input='   + input + ', output=' + output.DmsLatitude.DirectionType    + ', expected=' + expectedResult.DmsLatitude.DirectionType);
        equal(output.DmsLatitude.Degrees                ,expectedResult.DmsLatitude.Degrees             , 'N Degrees RESULT input='         + input + ', output=' + output.DmsLatitude.Degrees          + ', expected=' + expectedResult.DmsLatitude.Degrees);
        equal(output.DmsLatitude.Minutes                ,expectedResult.DmsLatitude.Minutes             , 'N Minutes RESULT input='         + input + ', output=' + output.DmsLatitude.Minutes          + ', expected=' + expectedResult.DmsLatitude.Minutes);
        equal(Math.round(output.DmsLatitude.Seconds)    ,Math.round(expectedResult.DmsLatitude.Seconds) , 'N Seconds RESULT input='         + input + ', output=' + output.DmsLatitude.Seconds          + ', expected=' + expectedResult.DmsLatitude.Seconds +'(round)');
  
        equal(output.DmsLongitude.DirectionType         ,expectedResult.DmsLongitude.DirectionType      , 'W DirectionType RESULT input='   + input + ', output=' + output.DmsLongitude.DirectionType   + ', expected=' + expectedResult.DmsLongitude.DirectionType);
        equal(output.DmsLongitude.Degrees               ,expectedResult.DmsLongitude.Degrees            , 'W Degrees RESULT input='         + input + ', output=' + output.DmsLongitude.Degrees         + ', expected=' + expectedResult.DmsLongitude.Degrees);
        equal(output.DmsLongitude.Minutes               ,expectedResult.DmsLongitude.Minutes            , 'W Minutes RESULT input='         + input + ', output=' + output.DmsLongitude.Minutes         + ', expected=' + expectedResult.DmsLongitude.Minutes);
        equal(Math.round(output.DmsLongitude.Seconds)   ,Math.round(expectedResult.DmsLongitude.Seconds), 'W Seconds RESULT input='         + input + ', output=' + output.DmsLongitude.Seconds         + ', expected=' + expectedResult.DmsLongitude.Seconds +'(round)');

    }
  
});


test("CoordinateConverter Formats -41.877518 146.760986", function () {

    var expectedResult : GeoConverter.Interfaces.ICoordinateDms = new GeoConverter.Model.CoordinateDmsInfo(
        new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.South, 41, 52 ,39.0648),
        new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.East, 146, 45, 39.5496)
    );

    var formats = new Array();//-41.877518 146.760986

    formats[0] = '-41.877518 146.760986';
    formats[1] = '-41.877518,146.760986';     
    formats[2] = '-41.8775180°, 146.7609860°';
    formats[3] = '-41°52.65108\', 146°45.65916\'';
    formats[4] = '-41°52\'39.0648", 146°45\'39.5496"';
    formats[5] = 'S41 52 39	E146 45 40';
    formats[6] = 'S 41 52.651	E 146 45.659';
    formats[7] = 'S41D 52 39	E146D 45 40';
    formats[8] = 'S41D 52.651	E146D 45.659';
    formats[9] = 'N41* 52.651\'  E146* 45.65916\''; 
    formats[10] = 'E146* 45.65916\'  N41* 52.651\''; 

    var dmsConverter: GeoConverter.Interfaces.IParseDms = new GeoConverter.Providers.DecimalAndDmsConverter();
    for (var i = 0; i < formats.length; i++){
        var input: string = formats[i];
        var output : GeoConverter.Interfaces.ICoordinateDms = dmsConverter.ParseCoordinateDms(input);
       
        equal(output.DmsLatitude.DirectionType          ,expectedResult.DmsLatitude.DirectionType       , 'N DirectionType RESULT input='   + input + ', output=' + output.DmsLatitude.DirectionType    + ', expected=' + expectedResult.DmsLatitude.DirectionType);
        equal(output.DmsLatitude.Degrees                ,expectedResult.DmsLatitude.Degrees             , 'N Degrees RESULT input='         + input + ', output=' + output.DmsLatitude.Degrees          + ', expected=' + expectedResult.DmsLatitude.Degrees);
        equal(output.DmsLatitude.Minutes                ,expectedResult.DmsLatitude.Minutes             , 'N Minutes RESULT input='         + input + ', output=' + output.DmsLatitude.Minutes          + ', expected=' + expectedResult.DmsLatitude.Minutes);
        equal(Math.round(output.DmsLatitude.Seconds)    ,Math.round(expectedResult.DmsLatitude.Seconds) , 'N Seconds RESULT input='         + input + ', output=' + output.DmsLatitude.Seconds          + ', expected=' + expectedResult.DmsLatitude.Seconds +'(round)');
  
        equal(output.DmsLongitude.DirectionType         ,expectedResult.DmsLongitude.DirectionType      , 'W DirectionType RESULT input='   + input + ', output=' + output.DmsLongitude.DirectionType   + ', expected=' + expectedResult.DmsLongitude.DirectionType);
        equal(output.DmsLongitude.Degrees               ,expectedResult.DmsLongitude.Degrees            , 'W Degrees RESULT input='         + input + ', output=' + output.DmsLongitude.Degrees         + ', expected=' + expectedResult.DmsLongitude.Degrees);
        equal(output.DmsLongitude.Minutes               ,expectedResult.DmsLongitude.Minutes            , 'W Minutes RESULT input='         + input + ', output=' + output.DmsLongitude.Minutes         + ', expected=' + expectedResult.DmsLongitude.Minutes);
        equal(Math.round(output.DmsLongitude.Seconds)   ,Math.round(expectedResult.DmsLongitude.Seconds), 'W Seconds RESULT input='         + input + ', output=' + output.DmsLongitude.Seconds         + ', expected=' + expectedResult.DmsLongitude.Seconds +'(round)');

    }
  
});


test("CoordinateConverter Formats 40.446454 -79.976875", function () {
    var input: string = "40.446454 -79.976875";
    var dmsConverter: GeoConverter.Interfaces.IParseDms = new GeoConverter.Providers.DecimalAndDmsConverter();

    var dmsExpectedResult: string = "N 40°26'47.2344\", W 79°58'36.75\"";
    var dmsOutput: GeoConverter.Interfaces.ICoordinateDms = dmsConverter.ParseCoordinateDms(input);
    equal(dmsOutput.ToString(), dmsExpectedResult, 'DMS  dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);

    var decimalExpectedResult: string = "40.446454, -79.976875";
    var decimalOutput: GeoConverter.Interfaces.ICoordinateDecimal = dmsOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult,  'DMS ToCoordinateDecimal decimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    
    var dmExpectedResult: string = "N 40°26.78724\", W 79°58.6125\"";
    var dmOutput: GeoConverter.Interfaces.ICoordinateDm = decimalOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult,  'Decimal ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);

    decimalOutput = dmOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult,  'Dm ToCoordinateDecimal DecimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    
    dmsOutput = decimalOutput.ToCoordinateDms();
    equal(dmsOutput.ToString(), dmsExpectedResult,  'Decimal ToCoordinateDms dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    
    dmOutput = dmsOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult,  'DMS ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);

});

test("CoordinateConverter Formats -41.877518, 146.760986", function () {
    var input: string = "-41.877518, 146.760986";
    var dmsConverter: GeoConverter.Interfaces.IParseDms = new GeoConverter.Providers.DecimalAndDmsConverter();

    var dmsExpectedResult: string = "S 41°52'39.0648\", E 146°45'39.5496\"";
    var dmsOutput: GeoConverter.Interfaces.ICoordinateDms = dmsConverter.ParseCoordinateDms(input);
    equal(dmsOutput.ToString(), dmsExpectedResult, 'DMS  dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);

    var decimalExpectedResult: string = "-41.877518, 146.760986";
    var decimalOutput: GeoConverter.Interfaces.ICoordinateDecimal = dmsOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult,  'DMS ToCoordinateDecimal decimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    
    var dmExpectedResult: string = "S 41°52.65108\", E 146°45.65916\"";
    var dmOutput: GeoConverter.Interfaces.ICoordinateDm = decimalOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult,  'Decimal ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);

    decimalOutput = dmOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult,  'Dm ToCoordinateDecimal DecimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    
    dmsOutput = decimalOutput.ToCoordinateDms();
    equal(dmsOutput.ToString(), dmsExpectedResult,  'Decimal ToCoordinateDms dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    
    dmOutput = dmsOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult,  'DMS ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);

});
